/*
 * Daniel Meekins
 * Testing file for sudoku_solver
 * test.c
 */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "cell.h"
#include "grid.h"
#include "solve.h"

void test_cell()
{
    cell_t *c;
    int i;
    
    c = cell_new(1);
    assert(c);
    cell_free(c);

    for(i = 0; i < CELL_MAX_NUM; i++)
    {
        c = cell_new(i);
        assert(c);
        assert(cell_get_num(c) == i);
        cell_free(c);
    }

    cell_t *c1, *c2;

    c = cell_new(0);
    c1 = cell_new(2);
    c2 = cell_new(2);
    cell_intersect(c, c1, c2);
    assert(cell_get_num(c) == 2);
    
    cell_set_num(c2, 4);
    assert(cell_get_num(c2) == 4);
    cell_union(c, c1, c2);
    assert(c->num == 10);

    c1->num = 0x19;
    c2->num = 0x08;
    cell_diff(c, c1, c2);
    assert(c->num == 0x11);

    cell_copy(c2, c);
    assert(c2->num == 0x11);

    c->num = 0xAA;
    cell_invert(c);
    assert(c->num == 0x155);

    c->num = 0xa;
    assert(cell_possible_count(c) == 2);
    
    cell_free(c);
    cell_free(c1);
    cell_free(c2);
}

void test_grid()
{
    grid_t *g1;
    g1 = grid_new(NULL);
    assert(g1);
    
}

void test_solve_num_inline()
{
    grid_t *g;
    uint nums[ROWS][COLS] =
    {
        { 0, 2, 3, 0, 0, 0, 0, 0, 1 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 4, 5, 2, 6, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
    };
    
    g = grid_new(nums);
    grid_update(g);
    //grid_print_full(g);
    solve_find_subgrid_num_inline(g);
    //printf("\n");
    //grid_print_full(g);
    int i = 0;
    for(i = 3; i < COLS; i++)
        assert(!cell_num_ispossible(g->cells[1][i], 1));
    assert(cell_num_ispossible(g->cells[1][1], 1));
    assert(cell_num_ispossible(g->cells[1][2], 1));
}

int main(void)
{
    test_cell();
    test_grid();
    test_solve_num_inline();
    
    return 0;
}
